package com.hs.homework_02.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.homework_02.entitiy.TbUser;
import com.hs.homework_02.service.TbUserService;
import com.hs.homework_02.mapper.TbUserMapper;
import com.hs.homework_02.utils.MD5Util;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 72793
* @description 针对表【tb_user】的数据库操作Service实现
* @createDate 2023-08-17 17:45:19
*/
@Service
public class TbUserServiceImpl extends ServiceImpl<TbUserMapper, TbUser>
    implements TbUserService{

    @Autowired
    private TbUserMapper mapper;

    @Override
    public TbUser login(TbUser user) {
        TbUser tbUser = mapper.selectByUsername(user.getUsername());
        if (tbUser == null) {
           throw new RuntimeException("用户名错误");
        }
        if (!tbUser.getPassword().equals(MD5Util.encode(user.getPassword()))) {
            throw new RuntimeException("密码错误");
        }
        return tbUser;
    }
}




